package com.zrm.zfcrpa.utils;

import com.zrm.zfcrpa.dao.entity.MyBaseExpiretion;
import com.zrm.zfcrpa.vo.ResultResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常
 */
@RestControllerAdvice
public class MyExptionHandler {
    private Logger logger = LoggerFactory.getLogger(MyExptionHandler.class);

    /**
     * 运行时异常捕获
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public ResultResponse<?> exptionhandler(RuntimeException e){
        logger.error("异常消息：{}",e.getMessage());
        return ResultResponse.error("操作失败",e.getMessage());
    }

    /**
     * 自定义异常捕获
     * @param e
     * @return
     */
    @ExceptionHandler(MyBaseExpiretion.class)
    public ResultResponse<?> exptionhandler(MyBaseExpiretion e){
        logger.error("异常消息：{}",e.getMessage());
        return ResultResponse.error(e.getData(),e.getMessage());
    }
}
